package modele;

import java.sql.Date;

public class Personne {

	// variables d'instance
	private int idPersonne;
	private String nom;
	private String prenom;
	private Date date_naissance;
	private String telephone;
	private String adresse;
	private String code_postal;
	private String ville;
	private String email;
	private String password;

	// constructeur contenant toutes les variables d'instance
	public Personne(int idPersonne, String nom, String prenom,
			Date date_naissance, String telephone, String adresse,
			String code_postal, String ville, String email, String password) {

		this.idPersonne = idPersonne;
		this.nom = nom;
		this.prenom = prenom;
		this.date_naissance = date_naissance;
		this.telephone = telephone;
		this.adresse = adresse;
		this.code_postal = code_postal;
		this.ville = ville;
		this.email = email;
		this.password = password;
	}

	// constructeur contenant toutes les variables d'instance sauf l'ID
	public Personne(String nom, String prenom, Date date_naissance,
			String telephone, String adresse, String code_postal, String ville,
			String email, String password) {

		this.nom = nom;
		this.prenom = prenom;
		this.date_naissance = date_naissance;
		this.telephone = telephone;
		this.adresse = adresse;
		this.code_postal = code_postal;
		this.ville = ville;
		this.email = email;
		this.password = password;
	}

	// constructeur contenant uniquement le nom et le pr�nom
	public Personne(String nom, String prenom) {

		this.nom = nom;
		this.prenom = prenom;
	}

	// constructeur vide
	public Personne() {

	}

	// getters et setters
	public String getNom() {
		return nom;
	}

	public void setNom(String nom) {
		this.nom = nom;
	}

	public String getPrenom() {
		return prenom;
	}

	public void setPrenom(String prenom) {
		this.prenom = prenom;
	}

	public Date getDate_naissance() {
		return date_naissance;
	}

	public void setDate_naissance(Date date_naissance) {
		this.date_naissance = date_naissance;
	}

	public String getTelephone() {
		return telephone;
	}

	public void setTelephone(String telephone) {
		this.telephone = telephone;
	}

	public String getAdresse() {
		return adresse;
	}

	public void setAdresse(String adresse) {
		this.adresse = adresse;
	}

	public String getCode_postal() {
		return code_postal;
	}

	public void setCode_postal(String code_postal) {
		this.code_postal = code_postal;
	}

	public String getVille() {
		return ville;
	}

	public void setVille(String ville) {
		this.ville = ville;
	}

	public String getEmail() {
		return email;
	}

	/**
	 * l'email doit contenir un @ pour �tre valider
	 * 
	 * @param email
	 */
	public void setEmail(String email) {
		if (!(email.contains("@"))) {
			email = "recommence";
		}
		this.email = email;
	}

	public String getPassword() {
		return password;
	}

	/**
	 * le mot de passe doit contenir au minimum 6 lettres
	 * 
	 * @param password
	 */
	public void setPassword(String password) {

		if ((password.length() < 6)) {
			password = "123456789";
		}
		this.password = password;
	}

	public int getIdPersonne() {
		return idPersonne;
	}

	public void setIdPersonne(int idPersonne) {
		this.idPersonne = idPersonne;
	}

	@Override
	public String toString() {
		return "Personne idPersonne=" + idPersonne + ", nom=" + nom
				+ ", prenom=" + prenom + ", date_naissance=" + date_naissance
				+ ", telephone=" + telephone + ", adresse=" + adresse
				+ ", code_postal=" + code_postal + ", ville=" + ville
				+ ", email=" + email + ", password=" + password + ".";
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((adresse == null) ? 0 : adresse.hashCode());
		result = prime * result
				+ ((code_postal == null) ? 0 : code_postal.hashCode());
		result = prime * result
				+ ((date_naissance == null) ? 0 : date_naissance.hashCode());
		result = prime * result + ((email == null) ? 0 : email.hashCode());
		result = prime * result + idPersonne;
		result = prime * result + ((nom == null) ? 0 : nom.hashCode());
		result = prime * result
				+ ((password == null) ? 0 : password.hashCode());
		result = prime * result + ((prenom == null) ? 0 : prenom.hashCode());
		result = prime * result
				+ ((telephone == null) ? 0 : telephone.hashCode());
		result = prime * result + ((ville == null) ? 0 : ville.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Personne other = (Personne) obj;
		if (adresse == null) {
			if (other.adresse != null)
				return false;
		} else if (!adresse.equals(other.adresse))
			return false;
		if (code_postal == null) {
			if (other.code_postal != null)
				return false;
		} else if (!code_postal.equals(other.code_postal))
			return false;
		if (date_naissance == null) {
			if (other.date_naissance != null)
				return false;
		} else if (!date_naissance.equals(other.date_naissance))
			return false;
		if (email == null) {
			if (other.email != null)
				return false;
		} else if (!email.equals(other.email))
			return false;
		if (idPersonne != other.idPersonne)
			return false;
		if (nom == null) {
			if (other.nom != null)
				return false;
		} else if (!nom.equals(other.nom))
			return false;
		if (password == null) {
			if (other.password != null)
				return false;
		} else if (!password.equals(other.password))
			return false;
		if (prenom == null) {
			if (other.prenom != null)
				return false;
		} else if (!prenom.equals(other.prenom))
			return false;
		if (telephone == null) {
			if (other.telephone != null)
				return false;
		} else if (!telephone.equals(other.telephone))
			return false;
		if (ville == null) {
			if (other.ville != null)
				return false;
		} else if (!ville.equals(other.ville))
			return false;
		return true;
	}
}